<template>

   <div>

        <el-form :model="form">
          <el-form-item label="用户名">
              <el-input v-model="form.username" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item label="密码">
              <el-input type="password" v-model="form.password" placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item label="">
              <template>
                  <el-button type="primary" @click="login">登录</el-button>
                  <el-button type="cancel">取消</el-button>
              </template>
          </el-form-item>
        </el-form>
   </div>

</template>

<script>
export default {
   data(){
       return {
          form:{}
       }
   },
   methods:{
       login(){
           //完成登录
           this.axios({
               url:"/login/",
               method:"POST",
               data:this.form
           }).then(resp=>{
               console.log(resp.data)
               alert(resp.data.msg)
               if(resp.data.code==300){
                   //跳转到 手机号绑定页
                   this.$router.push("/bind?uid="+resp.data.uid)
               }else if(resp.data.code==200){
                   //登录成功
                   sessionStorage.setItem("token",resp.data.token)
                   sessionStorage.setItem("username",this.form.username)
                   //回退
                   this.$router.go(-1)
               }
           })
       }
   },
   created(){

   }
}
</script>

<style>
.el-form{
    width:300px;
    margin: 30px auto;
}
</style>